package a01Collectiondemo1;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;

public class Test1 {
    public static void main(String[] args) {
        Collection<Student> coll = new ArrayList<>();
        Student s1 = new Student("张三", 18);
        Student s2 = new Student("李四", 19);
        coll.add(s1);
        coll.add(s2);
        Student s3 = new Student("张三", 18);

        System.out.println(coll.contains(s3));
        System.out.println(coll.isEmpty());
    }
}

class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}